<?php
class comment extends MY_Model{
    public function __construct() {
        parent::__construct();
    }
    //insert comment for object
    public function addComment($fields=array()){   
        if(empty($fields)){
            return false;
        }
        $this->db->insert('comments',$fields);
        return $this->db->insert_id();
    }
    
    //get comment by object id
    public function getComment($object_id,$valid=false){
        $this->db->where('object_id',$object_id);
        if($valid)
        $this->db->where('valid',$valid);
        $this->db->order_by('comment_id','desc');
        $query = $this->db->get('comments');
        return $query->result();
    }
    
    //delete comment
    public function deleteComment($comment_id=false){
        if($comment_id)
            $this->db->where('comment_id',$comment_id);
        $this->db->delete('comments');
            return $this->db->affected_rows();
    }
}
?>